# -*- coding: UTF-8 -*-
import requests
import json
import sys

class WXWork_SMS:

    # Markdown类型消息
    def send_msg_markdown(self,build_number, project_name, project_url):
        headers = {"Content-Type": "text/plain"}
        send_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=f1908388-e698-4245-8d83-1fb6d40ed2dd"
        report_url=project_url+"HTML_20Report"
        send_data = {
            "msgtype": "markdown",  # 消息类型，此时固定为markdown
            "markdown": {
                "content": "# <font color=\"warning\">**第"+build_number+"次构件**</font>\n" +  # 标题 （支持1至6级标题，注意#与文字中间要有空格）
                           "#### **去微软**\n" +  # 加粗：**需要加粗的字**
                           "> 类型：<font color=\"info\">测试用例执行</font> \n" +  # 引用：> 需要引用的文字
                           "> 执行人：<font color=\"info\">刘科航</font> \n" +  # 引用：> 需要引用的文字
                           "> 项目名称：<font color=\"warning\">"+project_name+"</font> \n" +  # 字体颜色(只支持3种内置颜色)
                           "> 测试报告链接：<font color=\"warning\">["+report_url+"]("+report_url+")</font>"  # 绿色：info、灰色：comment、橙红：warning
            }
        }

        res = requests.post(url=send_url, headers=headers, json=send_data)
        print(res.text)


if __name__ == '__main__':
    sms = WXWork_SMS()
    build_number = sys.argv[1]  # BUILD_NUMBER---第几次构件
    project_name = sys.argv[2]  # PROJECT_NAME---项目名称
    project_url = sys.argv[3]  # PROJECT_URL----项目地址
    # execute_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # Markdown类型消息
    sms.send_msg_markdown(build_number, project_name, project_url)
